package com.tengroup.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

@Configuration
public class MailConfig {

    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.qq.com"); // QQ 邮箱的 SMTP 服务器地址
        mailSender.setPort(465);            // SMTP SSL 加密端口
        mailSender.setUsername("2482970191@qq.com"); // QQ 邮箱地址
        mailSender.setPassword("hxumyilqxxisecdh"); // QQ 邮箱的授权码
        mailSender.setProtocol("smtp");

        // 配置 JavaMailSender 的邮件属性
        Properties properties = new Properties();
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.ssl.enable", "true");
        mailSender.setJavaMailProperties(properties);

        return mailSender;
    }
}
